package com.building.controller;

import com.building.common.R;
import com.building.controller.BaseController.BaseController;
import com.building.entity.Shopping;
import com.building.enums.REnum;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

/**
 *
 * 购物车控制器
 *
 * @author yinjiahui
 * @create 2021-04-11 17:23
 */
@RestController
@RequestMapping("shopping")
@Api(tags = "购物车控制器")
public class ShoppingController extends BaseController {

    /**
     *  根据用户id查询购物车中所有物品
     * @param userId
     * @return
     */
    @GetMapping("selectShoppingByUserId/{userId}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="根据用户id查询购物车中的商品",name="userId",dataType="Integer",required=true,value="用户id",defaultValue="这个是默认值，可以不写"),
    })
    @ApiResponses({
            @ApiResponse(code=400,message="请求参数没填好"),
            @ApiResponse(code=404,message="请求路径没有或页面跳转路径不对")
    })
    public R selectShoppingByUserId(@PathVariable("userId") Integer userId){
        return R.result(REnum.SUCCESS_QUERY,this.shoppingService.selectShoppingByUserId(userId));
    }


    /**
     *
     * 根据用户id和商品id删除商品
     *
     * @param userId
     * @param shoppingId
     * @return
     */
    @DeleteMapping("deleteShoppingByUserIdAndShoppingId/{userId}/{shoppingId}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="根据用户id删除购物车中的商品",name="userId",dataType="Integer",required=true,value="用户id",defaultValue="这个是默认值，可以不写"),
            @ApiImplicitParam(paramType="根据商品id删除购物车中的商品",name="shoppingId",dataType="Integer",required=true,value="商品id",defaultValue="这个是默认值，可以不写"),
    })
    @ApiResponses({
            @ApiResponse(code=400,message="请求参数没填好"),
            @ApiResponse(code=404,message="请求路径没有或页面跳转路径不对")
    })
    public R deleteShoppingByUserIdAndShoppingId(@PathVariable("userId") Integer userId,@PathVariable("shoppingId") Integer shoppingId){
        this.shoppingService.deleteShoppingByUserIdAndShoppingId(userId,shoppingId);
        return R.result(REnum.SUCCESS_DELETE);
    }

    /**
     *
     * 新增或修改商品到购物车中
     *
     * @param shopping
     * @return
     */
    @PostMapping("insertOrUpdateShopping")
    @ApiResponses({
            @ApiResponse(code=400,message="请求参数没填好"),
            @ApiResponse(code=404,message="请求路径没有或页面跳转路径不对")
    })
    public R insertOrUpdateShopping(@RequestBody Shopping shopping){
        return this.shoppingService.insertOrUpdateShopping(shopping);
    }


    /**
     *
     *  根据商品id查询购物车中商品的详细信息         //    回显
     *
     * @param shoppingId
     * @return
     */
    @GetMapping("selectShoppingByShopping/{shoppingId}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="根据商品id查询购物车中商品的详细信息",name="shoppingId",dataType="Integer",required=true,value="商品id",defaultValue="这个是默认值，可以不写"),
    })
    @ApiResponses({
            @ApiResponse(code=400,message="请求参数没填好"),
            @ApiResponse(code=404,message="请求路径没有或页面跳转路径不对")
    })
    public R selectShoppingByShopping(@PathVariable("shoppingId") Integer shoppingId){
        return R.result(REnum.SUCCESS_QUERY,this.shoppingService.selectShoppingByShopping(shoppingId));
    }

}
